/************************************************************************
 * @user wxl
 * @date 2016/2/28
 * @description 基础组件，用面向对象的方式来说，他是基类
 *************************************************************************
 * @copyright by wh  可以提供开源，但如果引用代码需标明出处
 ************************************************************************/
;(function(NS,$){
    var mgr = {};

    var _byId = function(id)
    {
        if(mgr[id])
            return mgr[id];
        else
            console.error("can't find widget by id = '"+ id +"'");
        return undefined;
    }
    var _registry = function(id, widget, force)
    {
        if(!id || id == "")
            return;
        if(!mgr[id])
            mgr[id] = widget;
        else
        {
            if(force)
            {
                mgr[id] = widget
                console.warn("force registry widget which id = '" + id +"'");
            }
            else
                console.error("the widget is existed which id = '" + id + "'");
        }
    }

    var _unregistry = function(id){
        if(mgr[id])
            mgr.slice(mgr.indexOf(id),1);
        else
            console.warn("unregistry widget failed, because can't find widget by id = '" + id + "' in widgetManager");
    }

    var _removeAll = function()
    {
        mgr = {};
    }
    NS.widgetMgr = {byId : function(id){return _byId(id)}
        ,registry : function(id, widget, force){_registry(id, widget, force)}
        ,unregistry : function(id){_unregistry(id)}
        ,removeAll : function(){_removeAll();}};
}(wh.ui, $))